Skip to content

FE-1604: Allow Voice interruption by speaking - #9550

Draft
kostandinang wants to merge 191 commits into
kostandin/fe-1580-harden-voice-safety-and-ux-on-the-unified-flue-routefrom
kostandin/fe-1604-allow-voice-interruption-by-speaking
Draft

FE-1604: Allow Voice interruption by speaking#9550
kostandinang wants to merge 191 commits into
kostandin/fe-1580-harden-voice-safety-and-ux-on-the-unified-flue-routefrom
kostandin/fe-1604-allow-voice-interruption-by-speaking

Conversation

@kostandinang

@kostandinang kostandinang commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Important

Current status: #9537 and #9564 are merged. Wait for the omitted settlement port in #9588 to be accepted, then recut this draft from the latest main as an independent sibling PR. Do not merge it meanwhile. FE-1604 medium VAD and interruption behavior remain this PR’s separate follow-up delta.

🌟 What is the purpose of this PR?

This PR lets a person interrupt Voice assistant playback by speaking without losing the interrupting utterance. It keeps the existing Your turn handoff as an optional half-duplex fallback and locally rejects likely false interruption transcripts before they become answers.

The change is stacked directly on #9531, which owns the shared Brunch Voice session, completed-transcript authority, canonical playback, and acknowledged manual handoff.

🔗 Related links

🚫 Blocked by

🔍 What does this change?

  • Keeps microphone capture active during canonical playback when Interruption by speaking is enabled.
  • Preserves immediate speech_started → response.cancel → output_audio_buffer.clear. Interruption never clears the input buffer, and transcript validation does not gate cancellation.
  • Preserves the same input item through completed transcription and submits the answer exactly once through the existing Brunch admission path.
  • Preserves an in-flight interruption and its provisional text when follow-on canonical speech is queued.
  • Retains an accepted interrupted answer while the previous Brunch turn settles and submits it when Voice input reopens.
  • Keeps the retained-answer confirmation visible if any later false transcript is rejected, including prompt regurgitation, self-echo, empty completions, and transcription failures.
  • Uses medium Semantic VAD eagerness while keeping response creation and interruption under Petrinaut control.
  • Adds a browser-saved, default-on Interruption by speaking checkbox to the existing playback menu.
  • Hides Your turn while automatic interruption is enabled and preserves its existing behavior when the preference is disabled.
  • Preserves mute, pause, Stop, end, reconnect, and exact replay behavior.
  • Updates the website README, Petrinaut Voice guide, and Voice architecture decision record; the PR retains its dedicated patch changeset.

Completed-transcript hardening

A false VAD event can cause gpt-4o-transcribe to repeat its vocabulary prompt or transcribe assistant playback. The Realtime bridge now runs a deterministic classifier only for completed interruption-originated transcripts, before retaining or submitting them:

  • Prompt regurgitation: reject strong ordered overlap with the configured transcription vocabulary, including the reported “SDCPN, stochastic Petri net, place, transition, arc, token, marking, guard, rate, distribution, parameter, subnet, scenario, and metric.” leak.
  • Self-echo: reject strong overlap with exact canonical text whose playback was active when interruption started. The snapshot excludes queued speech and conversation history and is cleaned up with the input/session lifecycle.
  • Comparison uses Unicode NFKC, lowercase, punctuation removal, and whitespace collapse. The conservative threshold is at least 80% ordered bigram overlap, with minimum lengths of eight tokens for prompt regurgitation and six for self-echo.
  • Short novel answers such as “stop”, “no”, and “wait” remain valid. Ordinary capture remains unchanged even when interruption is enabled. Comparison normalization does not change admitted wording, casing, or punctuation.
  • Rejected completions create no user turn, error, or pending answer. Provisional text for the rejected item is silently discarded, while an earlier retained answer and its confirmation remain visible. Diagnostics contain only operational metadata and a rejection reason, never transcript, prompt, or assistant text.

The transcription model and prompt remain unchanged. The prompt is shared between provider configuration and local validation to avoid drift. No extra model call, acoustic processing, debounce, or cancellation delay is introduced.

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

  • Modifies an npm-publishable library; kostandinang has added a patch changeset.

📜 Does this require a change to the docs?

  • Yes — libs/@hashintel/petrinaut/docs/ai-assistant.md, apps/petrinaut-website/README.md, and libs/@hashintel/brunch-agent/docs/adr/0009-openai-voice-ui-turn-shell.md document the Voice behavior and policy.

🕸️ Does this require a change to the Turbo Graph?

  • No Turbo execution-graph change is required.

⚠️ Known issues

  • False VAD can still stop playback even when the completed transcript is discarded. Preventing that interruption is explicitly out of scope.
  • The local classifier is conservative and heuristic; the real speaker/microphone witness is still required. Browser echo cancellation continues to use the existing media constraints.
  • Protocol tests establish immediate event ordering, input preservation, and local transcript rejection. Real-microphone interruption latency was not benchmarked.
  • The website unit suite has six pre-existing maximum-update-depth failures in voice-interview-control.test.tsx. These were reproduced before editing at the prior PR head, and the same six tests fail after hardening. This change does not fix or suppress them.
  • The latest local full-suite run also had two unrelated local-storage demo failures because the local Node runtime reported localStorage unavailable. These are separate from the Voice changes and did not appear in the prior PR CI run.

🛡 What tests cover this?

The prompt-leak, canonical-echo, queued-speech, retained-answer, and failed-transcript regressions were written first and observed failing before implementation. Coverage includes immediate cancellation, short novel answers, unchanged ordinary capture, duplicate completions, delayed/pending admission, active-playback-only snapshots, follow-on canonical speech, retained-answer display, and lifecycle cleanup.

Current verification at f69ac17034:

  • Focused Voice suites: 220 passed:

    yarn workspace @apps/petrinaut-website test:unit src/main/app/voice-interview src/server/voice src/voice-diagnostics.test.ts --exclude '**/voice-interview-control.test.tsx'

    The known-failing control suite is excluded only from this focused command; it is included in the full run below.

  • yarn workspace @apps/petrinaut-website test:unit: 355 passed, 8 failed. Six failures are the unchanged maximum-update-depth cases above; two are the local-runtime localStorage failures above.

  • yarn workspace @apps/petrinaut-website build: passed.

  • yarn workspace @apps/petrinaut-website lint:tsc: passed.

  • yarn workspace @apps/petrinaut-website lint:eslint: passed with zero errors and one existing set-state-in-effect warning in the unchanged control component.

  • yarn workspace @local/petrinaut-arch-docs lint:arch-docs: passed.

  • yarn lint:format and git diff --check: passed.

Earlier PR verification recorded 618/618 Petrinaut library unit tests and passing library TypeScript checks. Those library checks were not rerun for this website-only runtime hardening; the library change in this increment is documentation only.

❓ How to test this?

  1. Start Voice and open Voice playback options. Confirm Interruption by speaking is checked by default.
  2. While Brunch is speaking, begin answering, including short answers such as “stop”, “no”, or “wait”. Confirm playback stops immediately and the same utterance appears once without repetition, including if follow-on canonical speech is queued before transcription completes.
  3. Interrupt while the previous Brunch turn is still settling. Confirm an accepted answer shows Answer captured. Waiting for Brunch. and submits once input reopens. Confirm a later rejected echo does not erase that notice. The automated regression tests inject false vocabulary and canonical-echo completions and verify that neither becomes a turn or occupies the pending-answer slot.
  4. Uncheck Interruption by speaking. Confirm Your turn returns and the microphone stays closed during playback until the acknowledged handoff completes. Reload and confirm the preference is remembered.
  5. Exercise mute, pause, Stop, end, reconnect, Repeat question, and Read full response in both modes. Check speaker feedback separately: a rejected false transcript may still have stopped playback.

🎥 UX capture

This recording shows the default-on Interruption by speaking option, the Your turn fallback appearing when it is disabled, and the fallback disappearing when it is re-enabled.

fe-1604-voice-interruption-by-speaking.mp4

lunelson and others added 30 commits September 4, 2026 11:30
Signed-off-by: Lu Nelson <ln@hash.ai>
The built-app test still required the retired Brunch identity sentence, so its faux provider rejected the request before emitting any response and surfaced an empty-reasoning assertion instead.
The production-path test already proves skill activation, resource reads, server and client tools, and transcript behavior. Exact system-prompt sentences only coupled it to editorial changes and obscured failures behind empty downstream output.
Signed-off-by: Lu Nelson <ln@hash.ai>
Signed-off-by: Lu Nelson <ln@hash.ai>
Signed-off-by: Lu Nelson <ln@hash.ai>
Add a software-behavior/Gherkin paper plugin, extract the cross-plugin transformation and evidence invariant, and capture the prospective software-correctness/Dafny boundary for mission planning.

Amp-Thread-ID: https://ampcode.com/threads/T-01a05d1a-c858-722b-b53a-d0c448d14155
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@cursor

cursor Bot commented Sep 7, 2026

Copy link
Copy Markdown

PR Summary

High Risk
Removes the legacy /api/chat door and reshapes how Petrinaut reaches Brunch (identity headers, proxy, SDK hydration), while the persona harness drives the live production agent with strict admission semantics.

Overview
Brunch/Petrinaut conversation path is consolidated onto the ownership-guarded mounted Flue route (/agents/chat/:instanceId) via the browser ChatTransport and @flue/sdk. The app removes the server-side /api/chat handler and local Vite wiring that proxied it; the Petrinaut local dev config now proxies /agents/chat without stripping the stock API plugin.

Agent composition moves SDCPN modelling skills, Petrinaut tools, and prompts into @hashintel/brunch-agent + @hashintel/brunch-agent-plugin-sdcpn. The app ChatAgent only composes those packages plus app-owned ping and transport instructions. Runbook elicitation scripting is dropped from the app; headless construction and artifact helpers live under src/evaluations/.

A Pi persona evaluation harness adds brunch_turn (one in-character user utterance per turn into the production ChatAgent, submission-scoped read, optional mock or real-headless client-tool hosts, fail-closed after a bad admission) plus optional proof artifacts (snapshot.json, transcript, trace, manifest). A read-only browser observer attaches with ?mode=observe&principal=local&id=….

@hashintel/petrinaut patch changesets in this diff document durable Stop, Voice handoff/replay/notices, speak-to-interrupt, and voice input withdrawal/stop correlation—the implementation for those features is not in the brunch-agent files shown here.

Reviewed by Cursor Bugbot for commit f69ac17. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

this.#activeSubmission ||
!this.#chat.canAcceptInterviewAnswer ||
this.#chat.status !== "ready"
) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speech request still drops interrupting answers

Medium Severity

canonical-speech-requested still marks every accepted input item as playback-overlapping, even when interruption is enabled. The session keeps that item accepted and emits the completed transcript, so the words can appear, but the bridge then rejects them as unavailable with no notice. The controller also still clears partialText on speech request and output start, so an in-flight utterance can vanish if more canonical speech is queued after the user already started talking.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0666d5b. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 69cde87. Interruption-originated input items now remain accepted across later canonical speech requests, and the controller preserves their in-flight partial text through speech request and output-start events. Added bridge and controller regressions.

this.#transcriptItemId = null;
this.#transcriptKey = null;
this.#update({ inputNotice: "none", partialText: "" });
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

False rejection clears retained-answer notice

Low Severity

A later prompt-regurgitation or self-echo rejection always clears inputNotice and partialText. If an interrupting answer is already retained, the dock drops Answer captured. Waiting for Brunch. even though #pendingInterruption remains and will still submit. The user loses confirmation that the earlier answer is waiting.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0666d5b. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 69cde87. Rejected prompt-regurgitation and self-echo transcripts no longer clear a previously retained answer or its answer-pending notice, including across the later transcript event lifecycle.

@kostandinang
kostandinang force-pushed the kostandin/fe-1580-harden-voice-safety-and-ux-on-the-unified-flue-route branch from b53b100 to be56a18 Compare September 7, 2026 09:07
@kostandinang
kostandinang requested review from a team as code owners September 7, 2026 09:07
Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions github-actions Bot added area/deps Relates to third-party dependencies (area) area/tests New or updated tests type/legal Owned by the @legal team area/apps > hash.design Affects the `hash.design` design site (app) labels Sep 7, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 3 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 69cde87. Configure here.

this.#snapshot.inputNotice === "answer-pending"
? {}
: { inputNotice: "none", partialText: "" },
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later failures clobber retained answers

Medium Severity

A later false interruption that finishes empty or failed still replaces an answer-pending retained answer with not-heard and clears partialText. Only prompt-regurgitation and self-echo keep the waiting state, so a common failed VAD can hide a queued answer that will still submit.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 69cde87. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f69ac17. When an answer is already retained, later rejected false transcripts preserve its text and answer-pending notice; the transcription-failed session path now preserves it as well. Added red/green regressions for both empty and failed transcript event orderings.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/apps > hash.design Affects the `hash.design` design site (app) area/apps area/deps Relates to third-party dependencies (area) area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) area/tests New or updated tests type/eng > frontend Owned by the @frontend team type/legal Owned by the @legal team

Development

Successfully merging this pull request may close these issues.

2 participants